(function () {
    ExecuteOrDelayUntilScriptLoaded(_registerPostListView, 'clienttemplates.js');
})();

function _registerPostListView() {
    //Page Icon
    var pageIconFiledContext = {};
    pageIconFiledContext.Templates = {};
    pageIconFiledContext.Templates.Fields = {
        "PublishingPageIcon": {
            "View": pageIconViewTemplate,
        }
    };

    //Summary
    var summaryFiledContext = {};
    summaryFiledContext.Templates = {};
    summaryFiledContext.Templates.Fields = {
        "Summary": {
            "View": summaryViewTemplate,
        }
    };


    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(pageIconFiledContext);
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(summaryFiledContext);
};

//---Page Icon
function pageIconViewTemplate(ctx) {
    var icon = ctx.CurrentItem.PublishingPageIcon;
    return "<span class='imgPostList'>" + icon + "</span>";
}

//---Title
function summaryViewTemplate(ctx) {
    var summary = ctx.CurrentItem.Summary;
    if (summary.length > 100) {
        summary = summary.substring(0, 100);
    }
    return "" + summary + "...";
}